import { Component, OnInit } from '@angular/core';
import { UserManagementService } from '../user-management.service';

@Component({
    selector: 'itmp-manage-access-rights',
    templateUrl: './manage-access-rights.component.html',
    styleUrls: ['./manage-access-rights.component.css']
})
export class ManageAccessRightsComponent implements OnInit {
    renderHeader = [];
    // 右上角的打印，放大等按钮
    toolbarList = [{ className: 'icon-dayinfuyin-' }, { className: 'icon-xiazai' }];
    // pagination: any; // 分页数据的对象
    searchData: any; // 搜索数据的对象
    listOfData = []; // 列表数据的数组
    pagination = {
        totalEle: 25,
        currentPage: 1,
        currentSize: 10,
        pageSize: 10
    };
    isShowVietName = false;
    constructor(private UMService: UserManagementService) {}

    ngOnInit() {
        this.renderHeader = [
            {
                name: 'Access_Right_Name',
                key: null,
                value: 'Access_Right_Name',
                isChecked: true
            },
            {
                name: 'Description',
                key: null,
                value: 'description',
                isChecked: true
            }
        ];
        this.getData();
        this.initData();
        if (localStorage.getItem('itmp_lang') === 'vi') {
            this.isShowVietName = true;
        } else {
            this.isShowVietName = false;
        }
    }
    getData() {
        const queryData1 = {
            pageNum: this.pagination.currentPage,
            pageSize: this.pagination.pageSize
        };
        const query = this.UMService.getRoleTreeData(queryData1);
        query.subscribe(
            res => {
                this.listOfData = res.content.content;
            },
            err => {}
        );
    }
    // 初始化分页和搜索
    initData() {
        this.pagination = {
            totalEle: 25,
            pageSize: 999,
            currentPage: 1,
            currentSize: 10
        };
        this.searchData = {
            Access_Right_Name: null,
            description: null
        };
    }

    refresh() {
        this.getData();
    }
    click(i) {}

    // 分页控件改变事件
    onPageChange(e) {
        this.pagination.currentPage = e;
        this.getData();
    }
    onSizeChange(e) {
        this.pagination.currentSize = e;
        this.getData();
    }
}
